#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

struct Point
{
    int x;
    int y;
    int z;
};

bool compare(const Point &a, const Point &b)
{
    return a.z < b.z;
}

int main(int argc, char const *argv[])
{
    Point *points;
    double result;
    int n, i, t;
    scanf("%d", &n);
    points = new Point[n];
    for (i = 0; i < n; i++)
    {
        scanf("%d%d%d", &points[i].x, &points[i].y, &points[i].z);
    }
    sort(points, points + n, compare);
    result = 0;
    for (i = 0; i < n - 1; i++)
    {
        result += sqrt(pow(points[i + 1].x - points[i].x, 2) 
            + pow(points[i + 1].y - points[i].y, 2) 
            + pow(points[i + 1].z - points[i].z, 2)); 
    }
    printf("%.3lf", result);
    return 0;
}
